/***************************************************************************
**
**  <SYSZUXpinyin 1.0 , a chinese input method based on Qt for Embedded linux>
**  Copyright (C) <2010> <Gemfield> <gemfield@civilnet.cn>
**
**  This program is free software: you can redistribute it and/or modify
**  it under the terms of the GNU General Public License version 3 as published
**  by the Free Software Foundation.
**
**  This program is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**  GNU General Public License for more details.
**
**  You should have received a copy of the GNU General Public License
**  along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
**  If you have questions regarding the use of this file, please contact
**  Gemfield at gemfield@civilnet.cn or post your questions at
**  http://civilnet.cn/syszux/bbs
**
****************************************************************************/

#include "syszuxim.h"
#include "syszuxpinyin.h"
#include <QTextCodec>
#include <QPointer>
#include <QtCore>
#include <QtGui>
#include <QtGui/QInputContext>
#include <QPoint>
SyszuxIM::SyszuxIM()
{
        syszuxpinyin = new SyszuxPinyin(this);
        //syszuxpinyin->resize(800,480);
}
SyszuxIM::~SyszuxIM()
{
    syszuxpinyin->deleteLater();
}

void SyszuxIM::confirmString(QString gemfield)
{
        sendCommitString(gemfield);
}

void SyszuxIM::updateHandler(int type)
{


        switch(type)
        {
        case QWSInputMethod::Update:
            syszuxpinyin->show();
            syszuxpinyin->lineedit=QApplication::focusWidget();
            if(syszuxpinyin->sobjectname!=syszuxpinyin->lineedit->objectName())
            {
               // qDebug()<<syszuxpinyin->lineedit->metaObject()->className();
               // qDebug()<<syszuxpinyin->lineedit->objectName();
                syszuxpinyin->sobjectname=syszuxpinyin->lineedit->objectName();
                if(syszuxpinyin->lineedit->inherits("QLineEdit"))
                {
                    syszuxpinyin->lineEdit_window->setEchoMode(static_cast<QLineEdit*>(syszuxpinyin->lineedit)->echoMode());
                }
                if(QCursor::pos().x()<400)
                {
                   if(QCursor::pos().y()<300)
                   {
                       syszuxpinyin->move(200,300);
                   }
                   else
                   {
                       syszuxpinyin->move(200,0);
                   }
                }
                else
                {
                    if(QCursor::pos().y()<300)
                    {
                        syszuxpinyin->move(0,300);
                    }
                    else
                    {
                        syszuxpinyin->move(0,0);
                    }
                }

            }


           // }

            break;
        case QWSInputMethod::FocusOut:
            syszuxpinyin->hide();
            break;
        default:
            break;
        }
}


